package com.dylan.springcloud.provider.controller;

import com.dylan.springcloud.provider.model.User;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Dylan on 2018/10/12.
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {
    @Autowired
    private ObjectMapper objectMapper;

    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String addUser(User user) throws JsonProcessingException {
        System.out.println(objectMapper.writeValueAsString(user));
        return "添加成功了";
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String updateUser(@RequestBody User user) throws JsonProcessingException {
        System.out.println(objectMapper.writeValueAsString(user));
        return "修改成功了";
    }
}
